import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { config } from '../../shared/smartadmin.config';

declare var $: any;
@Component({
	selector: 'sa-config',
	templateUrl: './config.component.html',
	styleUrls:['./config.css']
})
export class ConfigComponent implements OnInit {
	tableData = [];		//表格数据
	specifyId = {
		picker1:'datetimepicker3',
		picker2:'datetimepicker4'
	};
	specifyTime = {
		startTime:'',
		endTime:'',
	};
	constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute ) {
		activatedRoute.queryParams.subscribe(queryParams => {
			
		});
	}

	ngOnInit(){
		this.table_search();
	}

	// 查询
	table_search(){
		this.jsonApiService.http_obj('sysConfig/querySysConfigList.html', null).subscribe(result => {
			this.tableData = result.data;
			this.tableData.map(item=>{	
				// data_share_switch:数据共享开关	is_controller:是否监控API	is_monitoring:是否控制API调用
				if(item.key == 'data_share_switch' || item.key == 'is_controller' || item.key == 'is_monitoring'){
					item.val1=item.val1==1?true:false;
				}
			});
		});
	}
	// 确定按钮
	confirm(item){
		let reqdata;
		if(item.key == 'data_share_switch' || item.key == 'is_controller' || item.key == 'is_monitoring' ){
			reqdata = {
				'id':item.id,
				'key':item.key,
				'val1':item.val1?'1':'0'
			}
		}else{
			reqdata = {
				'id':item.id,
				'key':item.key,
				'val1':item.val1
			}
		}
		this.jsonApiService.http_obj('sysConfig/updateSysConfigById.html',reqdata).subscribe(result => {
			this.jsonApiService.message(result.message);
			this.table_search();
		});
	}
}